import pymysql

db_if = {
    "host": "101.132.99.138",
    "port": 3306,
    "user": "root",
    "password": "Vv0IBQ5qST",
    "database": "ry-vue"
}


class ConnectMysql:
    def __init__(self, db_info: dict):
        self.db = pymysql.connect(
            **db_info, cursorclass=pymysql.cursors.DictCursor
        )
        # 创建游标
        self.cur = self.db.cursor()

    def get_result(self, sql1):
        self.cur.execute(sql1)
        result = self.cur.fetchall()
        self.db.commit()
        return result

    def operational_db(self, sql2):
        self.cur.execute(sql2)
        result = self.cur.fetchall()
        self.db.commit()
        return result

    def db_close(self):
        self.db.close()


if __name__ == '__main__':
    db = ConnectMysql(db_if)
    sql1 = 'select * from sys_user su where su.user_id = "1";'
    res = db.get_result(sql1)
    print(res)
    print(res[0]['user_id'])
    print(type(res[0]))
    db.db_close()
